/*
 * FIGURE 2 -- Plotting TX/IN Turnout/Absentee 2x2
 */

clear all

// Set Folder Path
gl path "~/Dropbox/CovidTurnout/replication"
set scheme plotplain // plotting style
// project, uses("$path/original_data/analysis_file.dta")
// project, uses("$path/modified_data/analysis_file_indiana.dta")

/* Prep TX data */

// Load data
use "$path/original_data/analysis_file.dta", clear

// Collapse vote mode by elec year, voter age
collapse voted [fw=obs], by(year age)
keep if mod(year, 4)==0 // keep presidential years

// TX turnout plot
binscatter voted age, ///
    name(tx_turnout) ///
	discrete linetype(connect) xline(64.5, lcolor(red)) ///
	ytitle("Turnout Per 100 People", size(small)) xtitle("Age at Election", size(small)) ///
    title("{bf: Turnout (Texas)}", size(small)) ///
	xlab(20(5)85) ylab(20(10)70) by(year) legend(off) ///
	scale(1.3) msymbol(oh oh oh oh oh oh) /// 
	lcolors(gs12 gs6 black) ///
	mcolors(gs12 gs6 black) ///
	text(62 50 "2020", size(small)) text(22 30 "2012", size(small)) text(30 23 "2016", size(small))
gr_edit .plotregion1.plot3.style.editstyle line(pattern(solid)) editcopy
gr_edit .plotregion1.plot2.style.editstyle line(pattern(solid)) editcopy
gr_edit .plotregion1.plot1.style.editstyle line(pattern(solid)) editcopy

// Load data
use "$path/original_data/analysis_file.dta", clear
// Collapse vote mode by elec year, voter age
collapse absentee [fw=obs] if voted==100, by(year age)
replace absentee = absentee/100
/* replace absentee = absentee/100 */
keep if mod(year, 4)==0 // keep presidential years

// TX absentee plot
binscatter absentee age, ///
    name(tx_absentee) ///
	discrete linetype(connect) xline(64.5, lcolor(red)) ///
	ytitle("Share of Ballots Cast Absentee", size(small)) xtitle("Age at Election", size(small)) ///
    text(.55 85 "2020", size(small)) /// 
	text(.37 85 "2016", size(small)) text(.19 85 "2012", size(small)) ///
    title("{bf: Share Absentee (Texas)}", size(small)) ///
	xlab(20(5)85) ylab(0(0.1)0.55) by(year) legend(off) ///
	scale(1.3) msymbol(oh oh oh) /// 
	lcolors(gs12 gs6 black) ///
	mcolors(gs12 gs6 black)
gr_edit .plotregion1.plot3.style.editstyle line(pattern(solid)) editcopy
gr_edit .plotregion1.plot2.style.editstyle line(pattern(solid)) editcopy
gr_edit .plotregion1.plot1.style.editstyle line(pattern(solid)) editcopy

/* Prep IN data */

use "$path/original_data/analysis_file_indiana.dta", clear

// Collapse vote mode by elec year, voter age
collapse voted [fw=obs], by(year age)
/* replace absentee = absentee/100 */
keep if mod(year, 4)==0 // keep presidential years

scatter voted age, ///
    name(in_turnout) ///
	connect(l) xline(64.5, lcolor(red)) ///
	ytitle("Turnout Per 100 People", size(small)) ///
	xtitle("Age at Election", size(small)) ///
    title("{bf: Turnout (Indiana)}", size(small)) ///
	xlab(20(5)85) ylab(20(10)70) legend(off) ///
    text(55 50 "2020", size(small)) ///
	scale(1.3) ///
	lc(black) ///
	mc(black) msymbol(oh)

use "$path/original_data/analysis_file_indiana.dta", clear

// Collapse vote mode by elec year, voter age
collapse absentee [fw=obs] if voted==100, by(year age)
/* replace absentee = absentee/100 */
keep if mod(year, 4)==0 // keep presidential years

keep if year == 2020
replace absentee = absentee/100

scatter absentee age, ///
    name(in_absentee) ///
	connect(l) xline(64.5, lcolor(red)) ///
	ytitle("Share of Ballots Cast Absentee", size(small)) xtitle("Age at Election", size(small)) ///
    title("{bf: Share Absentee (Indiana)}", size(small)) ///
	xlab(20(5)85) ylab(0(0.1)0.55) legend(off) ///
    text(.17 50 "2020", size(small)) ///
	scale(1.3) msymbol(oh oh oh) /// 
	lc(black) ///
	mc(black) ///

/*
 * Put everything together
 */

gr combine tx_absentee tx_turnout in_absentee in_turnout, xcommon rows(2) cols(2)
graph export "$path/output/turnout_combined_plot.pdf", replace
